<template>
  <div class="data-viz" v-if="phaseData">
    <svg class="gradient-defs" width="0" height="0">
      <defs>
        <linearGradient id="gradient" x1="0%" y1="0%" x2="100%" y2="100%">
          <stop offset="0%" style="stop-color:#3b82f6;stop-opacity:1" />
          <stop offset="100%" style="stop-color:#8b5cf6;stop-opacity:1" />
        </linearGradient>
      </defs>
    </svg>
    <div class="viz-container">
      <div class="viz-item" v-for="(item, index) in dataItems" :key="index">
        <div class="viz-icon">
          <i :class="item.icon"></i>
        </div>
        <div class="viz-content">
          <div class="viz-number" :data-target="item.value">{{ animatedValue(item.value) }}</div>
          <div class="viz-label">{{ item.label }}</div>
        </div>
        <div class="viz-progress">
          <div class="progress-circle" :class="{ 'completed': item.percentage >= 80 }">
            <svg class="progress-ring" width="60" height="60">
              <circle
                class="progress-ring-circle"
                stroke="rgba(59, 130, 246, 0.2)"
                stroke-width="4"
                fill="transparent"
                r="26"
                cx="30"
                cy="30"
              />
              <circle
                class="progress-ring-fill"
                stroke="url(#gradient)"
                stroke-width="4"
                fill="transparent"
                r="26"
                cx="30"
                cy="30"
                :stroke-dasharray="circumference"
                :stroke-dashoffset="circumference - (item.percentage / 100) * circumference"
                :style="{ animationDelay: (index * 0.2) + 's' }"
              />
            </svg>
            <div class="progress-icon" v-if="item.percentage >= 80">
              <i class="fas fa-check"></i>
            </div>
            <div class="progress-percentage" v-else>{{ Math.round(item.percentage) }}%</div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div v-else class="data-placeholder">
    <div class="placeholder-icon">
      <i class="fas fa-mouse-pointer"></i>
    </div>
    <p>点击左侧阶段卡片查看预计目标</p>
    <small>支持鼠标悬停或点击切换</small>
  </div>
</template>

<script>
export default {
  name: 'DataVisualization',
  props: {
    phaseData: {
      type: Object,
      default: null
    }
  },
  computed: {
    dataItems() {
      if (!this.phaseData) return []
      
      return [
        {
          icon: 'fas fa-users',
          value: this.phaseData.enterpriseCustomers,
          label: '企业客户',
          percentage: Math.min((this.phaseData.enterpriseCustomers / 8000) * 100, 100)
        },
        {
          icon: 'fas fa-tasks',
          value: this.phaseData.taskMatches,
          label: '任务匹配',
          percentage: Math.min((this.phaseData.taskMatches / 300000) * 100, 100)
        },
        {
          icon: 'fas fa-shield-alt',
          value: this.phaseData.systemStability,
          label: '系统稳定性',
          percentage: this.phaseData.systemStability
        },
        {
          icon: 'fas fa-chart-line',
          value: this.phaseData.efficiencyImprovement,
          label: '效率提升',
          percentage: this.phaseData.efficiencyImprovement
        }
      ]
    },
    circumference() {
      return 2 * Math.PI * 26 // 半径26的圆周长
    }
  },
  methods: {
    animatedValue(target) {
      return Math.floor(target * 0.8) // 简化版本，实际可以使用更复杂的动画
    }
  }
}
</script>

<style scoped>
.data-viz {
  padding: 2rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 20px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.data-placeholder {
  padding: 3rem 2rem;
  text-align: center;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
}

.placeholder-icon {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.3), rgba(14, 165, 233, 0.3));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
  animation: iconFloat 2s ease-in-out infinite;
}

.placeholder-icon i {
  font-size: 1.5rem;
  color: rgba(59, 130, 246, 0.8);
}

@keyframes iconFloat {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-10px); }
}

.data-placeholder p {
  color: rgba(255, 255, 255, 0.8);
  font-size: 1.1rem;
  margin: 0 0 0.5rem 0;
  font-weight: 500;
}

.data-placeholder small {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.9rem;
  font-style: italic;
}

.viz-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 2rem;
}

.viz-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 15px;
  border: 1px solid rgba(0, 212, 255, 0.2);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.viz-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(0, 212, 255, 0.1), transparent);
  transition: left 0.5s;
}

.viz-item:hover::before {
  left: 100%;
}

.viz-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 30px rgba(0, 212, 255, 0.3);
  border-color: rgba(0, 212, 255, 0.5);
}

.viz-icon {
  width: 60px;
  height: 60px;
  background: linear-gradient(45deg, #00d4ff, #5b73e8);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: iconPulse 2s infinite;
}

.viz-icon i {
  font-size: 1.5rem;
  color: white;
}

@keyframes iconPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.viz-content {
  flex: 1;
}

.viz-number {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(45deg, #00d4ff, #5b73e8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}

.viz-label {
  color: white;
  font-size: 0.9rem;
}

.viz-progress {
  display: flex;
  align-items: center;
  justify-content: center;
}

.progress-circle {
  position: relative;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.progress-ring {
  transform: rotate(-90deg);
  animation: rotateIn 0.8s ease-out forwards;
}

.progress-ring-circle {
  transition: stroke 0.3s ease;
}

.progress-ring-fill {
  stroke-linecap: round;
  transition: stroke-dashoffset 1s ease-out;
  animation: drawProgress 1.5s ease-out forwards;
}

.progress-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #10b981;
  font-size: 20px;
  animation: checkmark 0.6s ease-out 0.8s both;
}

.progress-percentage {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 12px;
  font-weight: 600;
  text-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
}

.progress-circle.completed .progress-ring-fill {
  stroke: #10b981;
}

@keyframes rotateIn {
  from {
    transform: rotate(-90deg) scale(0.8);
    opacity: 0;
  }
  to {
    transform: rotate(-90deg) scale(1);
    opacity: 1;
  }
}

@keyframes drawProgress {
  from {
    stroke-dashoffset: var(--circumference);
  }
  to {
    stroke-dashoffset: var(--final-offset);
  }
}

@keyframes checkmark {
  0% {
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.2);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}

@media (max-width: 768px) {
  .viz-container {
    grid-template-columns: 1fr;
  }
  
  .viz-item {
    flex-direction: column;
    text-align: center;
  }
}
</style>
